package sandbox.vaadin.skiller.skillgroupmanager;

import sandbox.session.DefaultSessionContext;
import sandbox.vaadin.skiller.entity.Skill;
import sandbox.vaadin.skiller.entity.Skillgroup;

import com.vaadin.addon.jpacontainer.EntityItem;
import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.util.filter.Compare;

class SkillgroupManagerContext
{
	private JPAContainer<Skillgroup> skillgroupContainer;
	private EntityItem<Skillgroup> skillgroupSelectedEntityItem;

	private JPAContainer<Skill> skillContainer;
	private EntityItem<Skill> skillSelectedEntityItem;

	private Filter skillContainerFilter;

	SkillgroupManagerContext()
	{
		skillgroupContainer = new JPAContainerSkillgroup();
		skillgroupContainer.setEntityProvider(
				DefaultSessionContext.get().getSkillgroupEntityProvider());
		skillgroupContainer.setParentProperty("parent");

		skillContainer = new JPAContainerSkill();
		skillContainer.setEntityProvider(
				DefaultSessionContext.get().getSkillEntityProvider());
		skillContainer.addNestedContainerProperty("skillgroup.id");
		
		skillContainerFilter = new Compare.Equal("skillgroup.id", -1);
	}

	public EntityItem<Skillgroup> getSkillgroupSelectedEntityItem()
	{
		return skillgroupSelectedEntityItem;
	}

	public void setSkillgroupSelectedEntityItem(
	    EntityItem<Skillgroup> skillgroupSelectedEntityItem)
	{
		this.skillgroupSelectedEntityItem = skillgroupSelectedEntityItem;

		skillContainerFilter =
				new Compare.Equal(
						"skillgroup.id", skillgroupSelectedEntityItem.getEntity().getId());

		skillContainer.removeAllContainerFilters();
		skillContainer.addContainerFilter(skillContainerFilter);
	}

	public EntityItem<Skill> getSkillSelectedEntityItem()
	{
		return skillSelectedEntityItem;
	}

	public void setSkillSelectedEntityItem(EntityItem<Skill> skillSelectedEntityItem)
	{
		this.skillSelectedEntityItem = skillSelectedEntityItem;
	}

	public JPAContainer<Skillgroup> getSkillgroupContainer()
	{
		return skillgroupContainer;
	}

	public JPAContainer<Skill> getSkillContainer()
	{
		return skillContainer;
	}
}